package com.xiaoyun.service.impl;

import com.xiaoyun.mapper.StuMapper;
import com.xiaoyun.pojo.Stu;
import com.xiaoyun.service.StuService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
public class StuServiceImpl implements StuService {

    private final StuMapper stuMapper;

    @Override
    public Stu getStuInfo(int id) {
        return stuMapper.selectByPrimaryKey(id);
    }

    @Transactional
    @Override
    public void saveStu() {
        Stu stu = new Stu();
        stu.setName("jack");
        stu.setAge(19);
        stuMapper.insert(stu);
    }

    @Transactional
    @Override
    public void updateSut(int id) {
        Stu stu = new Stu();
        stu.setName("jack");
        stu.setAge(19);
        stu.setId(id);
        stuMapper.updateByPrimaryKey(stu);
    }

    @Transactional
    @Override
    public void deleteStu(int id) {
        stuMapper.deleteByPrimaryKey(id);
    }
}
